﻿export function toggle(el, index, collapse) {
    var li = $(el).children('li')[index];
    var $el = $(li).children('.food-header').next();
    if (collapse) {
        $el.slideUp();
    }
    else {
        $el.slideDown();
    }
}

export function toggle_all(el, collapse, level) {
    var state = ":hidden";
    if (collapse) {
        // 为真时表示全部收起
        state = ":visible";
    }

    var $items = null;
    if (level === 'day') {
        $items = $(el).find('.food-header');
    }
    else if (level === 'time') {
        $items = $(el).find('.s-food-time > .food-item > .food-header');
    }
    else if (level === 'menu') {
        $items = $(el).find('.s-food-menu > .food-item > .food-header');
    }

    $items.each(function (index, header) {
        var $header = $(header);
        var $body = $header.next();
        if ($body.is(state)) {
            $header.trigger('click');
        }
    });
}
